package com.ampaiva.dao;

import java.util.LinkedList;
import java.util.List;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class Dao<T> {

    // TEMP!!!!
    private static final String __TABLE = "Shippers";
    private static final String __COLUMNS[] = { "CompanyName", "phone" };
    //
    Context context;
    private final String zipFile;
    private final String dbName;

    public Dao(Context context, String zipFile, String dbName) {
        this.context = context;
        this.zipFile = zipFile;
        this.dbName = dbName;
    }

    public List<T> getList() {
        MyDroidSQLDatabase myDroidSQLDatabase = new MyDroidSQLDatabase(context, zipFile, dbName);
        myDroidSQLDatabase.open();
        List<T> shippers = new LinkedList<T>();
        SQLiteDatabase database = myDroidSQLDatabase.getSqlLiteDatabase();
        Cursor cursor = database.query(__TABLE, __COLUMNS, null, null, null, null, null);
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            // T shipper = new T();
            // shipper.setCompanyName(cursor.getString(0));
            // shipper.setPhone(cursor.getString(1));
            // shippers.add(shipper);
            cursor.moveToNext();
        }
        cursor.close();
        Log.v(Dao.class.getSimpleName(), "ShipperDao returning " + shippers.size() + " shippers");

        myDroidSQLDatabase.close();
        return shippers;
    }

}
